/********************init.htm**************/

function organn_deleteOrgan(code, name) {
	var url = create_url('organn-delete');
	organn_aidExecuteOrgan(code, url);
}

function organn_aidExecuteOrgan(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				jConfirm('操作成功!', '提示', function(r) {
					if(r == true){
						organn_queryOrgan();
					}
				});
				
			} else {
				jConfirm('操作失败!', '提示');
			}
		}
	});
}

function organn_selectParent() {
	var url = create_url('organn-aidQueryInit');
	var parm = {'id':'parentCode', 'name':'parentName'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function organn_loadSonList(code) {
	var url = create_url('organn-sonList');
	var parm = {'code':code};
	var sonTd = $('#orgaSonTd_' + code);
	sonTd.html(sys_loading_img);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sonTd.html(result);
		}
	});
}

function organn_editOrgan(code, parentCode) {
	var url = create_url('organn-edit');
	var parm = {'code':(null != code ? code : ''), 'parentCode':(null != parentCode ? parentCode : '')};
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			$('#editOrganTd').html(result);
		}
	});
}
function saveOrgan() {
	var parm = $('#editPsiOrganForm').serialize();
	var url = create_url('organn-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('organn');
			} else if (result == 'parameter_error') {
				sys_msg('父机构不能为空!');
			} else if (result == 'failure') {
				sys_msg('父机构不能选择自己!');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}

function selectParent() {
	var url = create_url('organn-aidInit');
	var parm = {'id':'pc', 'name':'pn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}
/***********edit.html****************/
function organn_saveOrgan() {
	var parm = $('#editPsiOrganForm').serialize();
	var url = create_url('organn-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('organn');
			} else if (result == 'parameter_error') {
				sys_msg('父机构不能为空!', '提示');
			} else if (result == 'failure') {
				sys_msg('父机构不能选择自己!', '提示');
			} else {
				sys_msg('操作失败!', '提示');
			}
		}
	});
}

function organn_selectParent() {
	var url = create_url('organn-aidInit');
	var parm = {'id':'pc', 'name':'pn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}